﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace NutriLeaf.Web.Core.Food
{
    public class IFoodCountry
    {
        void AddFoodToCountry(int foodId, int countryId, ref Model.NutriLeafDBEntities context) {
            Model.FoodCountry country = new Model.FoodCountry();
            country.FoodID = foodId;
            country.CountryID = countryId;
            context.FoodCountries.AddObject(country);
            context.SaveChanges();
        }

        void RemoveFoodFromCountry(int foodId, int countryId, ref Model.NutriLeafDBEntities context) { 
        if(context.FoodCountries.Where(p=>p.FoodID==foodId && p.CountryID==countryId).Count()!=0){

            context.FoodCountries.DeleteObject(context.FoodCountries.Where(p => p.FoodID == foodId && p.CountryID == countryId).First());
            context.SaveChanges();
        }

        }

        List<Model.Country> GetFoodCountries(int foodId, ref Model.NutriLeafDBEntities context) {
            List<Model.Country> country = new List<Model.Country>();
            List<Model.FoodCountry> foodcountry = context.FoodCountries.Where(p=>p.FoodID==foodId).ToList();
            foreach (Model.FoodCountry f in foodcountry) {
                country.Add(f.Country);
            }
            return country;
          
        }

    }
}